import matplotlib.pyplot as plt
import numpy as np

print('interval.')
fig = plt.figure(figsize=(4, 2))
fig.subplots_adjust(left=0, right=1, top=1, bottom=0)
ax = fig.add_subplot()
ax.spines['top'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.set_xticks([])
ax.set_yticks([])
ax.plot([-0.5, 16.5, 16.5, -0.5, -0.5], [7, 7, -7, -7, 7], color='black', linewidth=0.5)
ax.plot([0, 16], [0.5, 0.5], color='black', linewidth=0.5)
ax.plot([0, 16], [-0.5, -0.5], color='black', linewidth=0.5)


for n in range(0, 17, 4):
    ax.plot([n, n], [-0.5, -1], color='black', linewidth=0.5)
    ax.arrow(n, -5, 0, 3, head_width=0.2, head_length=0.3, color='black')


x = np.array([0, 4.8, 5.7, 6.4, 7.3, 8.2, 8.7, 9.2, 9.7, 10.2, 10.7, 11.2, 11.7, 12.2])
for n in x:
    ax.plot([n, n], [0.5, 1], color='black', linewidth=0.5)
    ax.arrow(n, 5, 0, -3, head_width=0.2, head_length=0.3, color='black')
    # ax.plot([n, n], [-0.5, -1], color='black', linewidth=0.5)
    # ax.arrow(n, -5, 0, 3, head_width=0.2, head_length=0.3)
x = np.linspace(12.5, 15.8, 12)
for n in x:
    ax.plot([n, n], [0.5, 1], color='black', linewidth=0.5)
    ax.arrow(n, 5, 0, -3, head_width=0.2, head_length=0.3)
    # ax.plot([n, n], [-0.5, -1], color='black', linewidth=0.5)
    # ax.arrow(n, -5, 0, 3, head_width=0.2, head_length=0.3)


ax.text(6, -6.5, '固定的控制周期', fontsize=8)
ax.text(6, 5.5, '变化的脉冲周期', fontsize=8)
ax.set_ylim([-10, 10])
plt.show()
print('finished.')
